/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2022-11-30
 * Time: 11:19
 */
class RunnableImpl implements Runnable {

    private int ticket = 10000;//票的张数

    @Override
    public synchronized void run() {
        while (ticket>0) {

            System.out.println(Thread.currentThread().getName() + "正在卖第" + ticket-- + "张票");
            try {//因为sleep有异常这里用try...catch解决异常
                Thread.sleep(10);//让程序休眠10毫秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

//运行的类
public class RunnableMain {

    public static void main(String[] args) {

        RunnableImpl run = new RunnableImpl();//创建实现类对象

        Thread t0 = new Thread(run);
        Thread t1 = new Thread(run);

        t0.start();//开启多线程
        t1.start();
    }
}